<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function unique(arr) {
        //创建新数组
        var newArr = []
        //判断是不是数组
        if (Array.isArray(arr) === false) return '不是数组'

        //遍历旧数组，用indexOf()看新数组里有没有，结果为-1就是没有，就保存到新数组
        for (var i = 0; i < arr.length; i++) {
          if (newArr.indexOf(arr[i]) === -1) newArr.push(arr[i])
        }
        return newArr
      }
      var res = unique([11, 23, 33, 11, 23, 4])
      console.log(res)
    </script>
  </body>
</html>
